public class Test {
    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        int lenL = 0;
        int lenS = 0;
        ListNode curL = pHead1;
        ListNode curS = pHead2;

        while(curL !=  null) {
            curL = curL.next;
            lenL++;
        }

        while(curS !=  null) {
            curS = curS.next;
            lenS++;
        }

        curL = pHead1;
        curS = pHead2;
        int len = lenL - lenS;
        if(len < 0) {
            len = lenS - lenL;
            curL = pHead2;
            curS = pHead1;
        }

        while(len != 0) {
            curL = curL.next;
            len--;
        }

        while(curL != curS) {
            curL = curL.next;
            curS = curS.next;
        }

        if(curL == null) {
            return null;
        }
        return curS;

    }
    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        int lenL = 0;
        int lenS = 0;
        ListNode curL = pHead1;
        ListNode curS = pHead2;

        while(curL !=  null) {
            curL = curL.next;
            lenL++;
        }

        while(curS !=  null) {
            curS = curS.next;
            lenS++;
        }

        curL = pHead1;
        curS = pHead2;
        int len = lenL - lenS;
        if(len < 0) {
            len = lenS - lenL;
            curL = pHead2;
            curS = pHead1;
        }

        while(len != 0) {
            curL = curL.next;
            len--;
        }

        while(curL != curS) {
            curL = curL.next;
            curS = curS.next;
        }

        if(curL == null) {
            return null;
        }
        return curS;

    }
}
